<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>资源中心</title>
    <link rel="icon" href="/docs/favicon.ico" type="image/x-icon">
    <!-- GitHub Markdown 样式 -->
    <link rel="stylesheet" href="public/github-markdown.min.css">

    <!-- 引入 marked.js 用于 Markdown 转换 -->
    <script src="public/marked.min.js"></script>
    <style>
        /* 全局设置防止水平滚动 */
        html, body {
            margin: 0;
            padding: 0;
            overflow-x: hidden;
            width: 100%;
            box-sizing: border-box;
            -webkit-overflow-scrolling: touch; /* 平滑滚动体验 */
        }

        * {
            box-sizing: inherit;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f5f9;
        }

        blockquote {
            background: #deecff;
            padding: 10px !important;
        }

        pre {
            background: #deecff !important;
        }

        .container {
            width: 100%;
            max-width: 800px;
            margin: auto;
            padding: 0 12px 30px 12px;
            box-sizing: border-box;
        }

        .preview-header {
            display: flex;
            align-items: center;
        }

        .back-button {
            background: none;
            border: none;
            font-size: 1.2em;
            color: #007bff;
            cursor: pointer;
            margin-right: 10px;
            padding: 0px;
        }

        #markdown-title {
            color: #007bff;
        }

        .markdown-body {
            background-color: #f5f5f9;
            line-height: 1.6;
            width: 100%;
            padding: 0;
            margin: 0;
        }

        .markdown-body h1, .markdown-body h2, .markdown-body h3 {
            color: #2c3e50;
        }

        .markdown-body code,
        .markdown-body pre {
            word-wrap: break-word;
            white-space: pre-wrap;
        }

        .markdown-body code {
            padding: 2px 4px;
            border-radius: 4px;
        }

        .markdown-body pre {
            padding: 10px;
            overflow-x: auto;
        }

        h2.title {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
            font-size: 1.8rem;
        }

        .file-list {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
            gap: 16px;
            padding: 0;
            margin: 0;
        }

        .file-item {
            background: white;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.07);
            text-align: center;
            padding: 16px;
            transition: all 0.3s ease-in-out;
        }

        .file-item:hover {
            background-color: #b5ccf8;
            transform: translateY(-4px) scale(1.02);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
        }

        .icon {
            font-size: 2.2rem;
            margin-bottom: 8px;
            transition: color 0.3s ease;
        }

        .label {
            font-size: 1rem;
            color: #333;
            word-break: break-all;
            line-height: 1.3;
        }

        .file-list a {
            text-decoration: none;
            color: inherit;
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 100%;
        }

        .footer {
            text-align: center;
            margin-top: 40px;
            font-size: 0.9rem;
            color: #aaa;
        }

        /* 返回首页按钮样式 */
        #backToHomeBtn {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 100;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            font-size: 18px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.2);
            cursor: pointer;
            display: none;
            transition: opacity 0.3s ease;
        }
    </style>
</head>
<body>
<div class="container">
    <div id="file-list">
        <h2 class="title">📚 资源中心</h2>
        <div class="file-list">
            <div class="file-item"><a href="#" onclick="loadMarkdown('常用网站.md')"><div class="icon">🌐</div><div class="label">常用网站</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Windows.md')"><div class="icon">🖥️</div><div class="label">Windows</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Windows下载.md')"><div class="icon">💾</div><div class="label">Windows下载</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Bat.md')"><div class="icon">⚙️</div><div class="label">Bat脚本</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('CentOS.md')"><div class="icon">🐧</div><div class="label">CentOS</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Docker.md')"><div class="icon">🐋</div><div class="label">Docker</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Java.md')"><div class="icon">☕</div><div class="label">Java</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Kubernetes.md')"><div class="icon">⎈</div><div class="label">Kubernetes</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Maven.md')"><div class="icon">📦</div><div class="label">Maven</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Mysql.md')"><div class="icon">🛢️</div><div class="label">MySQL</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Nginx.md')"><div class="icon">🔄</div><div class="label">Nginx</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Oracle.md')"><div class="icon">🗄️</div><div class="label">Oracle</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Redis.md')"><div class="icon">🔴</div><div class="label">Redis</div></a></div>
            <div class="file-item"><a href="#" onclick="loadMarkdown('Tomcat.md')"><div class="icon">🛠️</div><div class="label">Tomcat</div></a></div>
            <div class="file-item"><a href="/docs/Totp.html"><div class="icon">🔐</div><div class="label">TOTP</div></a></div>
        </div>
        <div class="footer">
            &copy; 2025 资源中心 | 仅供个人使用
        </div>
    </div>

    <!-- Markdown 预览区域 -->
    <div id="markdown-preview" style="display: none;">
        <div class="preview-header">
            <button onclick="goBack()" class="back-button">⬅️</button>
            <h2 id="markdown-title" class="preview-title"></h2>
        </div>
        <div id="markdown-output" class="markdown-body"></div>
    </div>

    <!-- 返回首页按钮 -->
    <button id="backToHomeBtn" onclick="goBack()">🏠</button>
</div>

<script>
    let scrollHandler = null;

    // 加载指定的 Markdown 文件
    function loadMarkdown(filename) {
        const output = document.getElementById("markdown-output");
        const previewContainer = document.getElementById("markdown-preview");
        const titleElement = document.getElementById("markdown-title");

        // 设置标题
        titleElement.textContent = filename.split(".")[0];

        // 显示加载提示
        output.innerHTML = "<p>加载中...</p>";

        // 显示预览区域，隐藏文件列表
        previewContainer.style.display = "block";
        document.getElementById("file-list").style.display = "none";

        // 使用 fetch 加载 .md 文件
        fetch(filename)
            .then(response => {
                if (!response.ok) {
                    throw new Error(`无法加载 ${filename}`);
                }
                return response.text();
            })
            .then(text => {
                // 使用 marked.js 转换 Markdown
                output.innerHTML = marked.parse(text);

                // 启动滚动监听
                setupBackToTopButton();
            })
            .catch(error => {
                output.innerHTML = `<p style="color: red;">错误：${error.message}</p>`;
            });
    }

    // 返回到文件列表
    function goBack() {
        document.getElementById("markdown-preview").style.display = "none";
        document.getElementById("file-list").style.display = "block";

        // 隐藏按钮并移除滚动监听
        const btn = document.getElementById("backToHomeBtn");
        btn.style.display = "none";

        if (scrollHandler) {
            window.removeEventListener("scroll", scrollHandler);
            scrollHandler = null;
        }
    }

    // 设置返回首页按钮逻辑
    function setupBackToTopButton() {
        const btn = document.getElementById("backToHomeBtn");
        btn.style.display = "none"; // 默认不显示

        scrollHandler = () => {
            if (window.scrollY > 300) {
                btn.style.display = "block";
            } else {
                btn.style.display = "none";
            }
        };

        window.addEventListener("scroll", scrollHandler);
    }
</script>
</body>
</html>